package route

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"net/http"
	"oolee.com/primary/common"
)

func registryLoginRoute(route *gin.RouterGroup) {
	loginGroup := route.Group("/login")
	login(loginGroup)
}

func login(route *gin.RouterGroup) {
	route.POST("/", func(context *gin.Context) {
		var form LoginForm
		if context.ShouldBindWith(&form, binding.JSON) != nil {
			context.JSON(http.StatusBadRequest, common.Fail())
		}
		result := new(common.Result)
		context.JSON(200, result.Ok(nil))
	})
}

type LoginForm struct {
	Name string `form:"name" binding:"required"`
	Pwd  string `form:"pwd" binding:"required"`
}

func init() {
	fmt.Println("init ...")
}

//func main() {
//	route := gin.Default()
//	route.POST("/login", func(c *gin.Context) {
//		var form LoginForm
//		if c.ShouldBindWith(&form, binding.JSON) == nil {
//			if form.Name == "oolee" && form.Pwd == "123456" {
//				c.JSON(200, gin.H{"status": "success"})
//			} else {
//				c.JSON(401, gin.H{"status": "fail"})
//			}
//		}
//	})
//	if route.Run(common.ADDRESS) != nil {
//		return
//	}
//}
